/*
 * gpu_util.h
 *
 *  Created on: Jun 21, 2013
 *      Author: tifuera
 */
#include <cuda_runtime.h>
#include <cublas_v2.h>
#include <stdio.h>

#include "sparse_band.h"

#ifndef GPU_UTIL_H_
#define GPU_UTIL_H_

#define min(X,Y) (((X)<(Y))?(X):(Y))
#define max(X,Y) (((X)>(Y))?(X):(Y))
#define checkCudaErrors(err)           __checkCudaErrors (err, __FILE__, __LINE__)

inline void __checkCudaErrors(cudaError err, const char *file, const int line)
{
	if (cudaSuccess != err)
	{
		fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n", file, line,
				(int) err, cudaGetErrorString(err));
		//exit(-1);
	}
}

void initCublasHandle(cublasHandle_t* handle);

void copyBandMatrixFromDevice(gpu_symm_band_matrix gpu_matrix, double* h_matrix,
		cublasHandle_t handle);

void copyBandMatrixToDevice(double *h_matrix, gpu_symm_band_matrix * gpu_matrix,
		cublasHandle_t handle);

#endif /* GPU_UTIL_H_ */
